package com.example.netty.channel;

import com.example.netty.handler.MessageBeanDecoder;
import com.example.netty.handler.MessageDecoder;
import com.example.netty.handler.MessageEncoder;
import com.example.netty.handler.MyChannelInboundHandler;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

/**
 * @Author : lichong
 * @description :
 * @Date Create in 14:56 2020/1/12
 * @Modified By :
 **/
public class BootNettyChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        pipeline.addLast(new IdleStateHandler(6 * 60, 0, 0));
        //日志处理器
        //pipeline.addLast("logging", new LoggingHandler(LogLevel.INFO));
        //byte转成string解码器
        pipeline.addLast("byteDecoder", new MessageDecoder());
        //信息编码器
        pipeline.addLast("encoder", new MessageEncoder());
        //String转成实体解码器
        pipeline.addLast("beanDecoder", new MessageBeanDecoder());
        //业务处理器
        pipeline.addLast("objectDecoder", new MyChannelInboundHandler());
    }
}
